#ifndef BOOKMARKMANAGER_H
#define BOOKMARKMANAGER_H

#include <QObject>
#include <QString>
#include <QList>
#include <QDateTime>
#include <QSqlDatabase>

struct BookmarkItem {
    int id;
    QString name;
    QString query;
    QDateTime created;
    QString databaseName;
    
    BookmarkItem() : id(0) {}
    BookmarkItem(const QString &n, const QString &q, const QDateTime &c, const QString &dbName)
        : id(0), name(n), query(q), created(c), databaseName(dbName) {}
};

class BookmarkManager : public QObject
{
    Q_OBJECT

public:
    explicit BookmarkManager(QObject *parent = nullptr);
    ~BookmarkManager();
    
    bool initialize(const QString &databasePath = QString());
    bool addBookmark(const QString &name, const QString &query, const QString &databaseName);
    bool removeBookmark(int id);
    bool updateBookmark(int id, const QString &name, const QString &query);
    QList<BookmarkItem> getBookmarks() const;
    QList<BookmarkItem> searchBookmarks(const QString &searchTerm) const;
    BookmarkItem getBookmarkById(int id) const;
    bool clearAllBookmarks();
    int bookmarkCount() const;
    
signals:
    void bookmarksChanged();

private:
    bool createTables();
    QString getDefaultDatabasePath() const;
    
    QSqlDatabase m_database;
    QString m_databasePath;
    bool m_initialized;
};

#endif // BOOKMARKMANAGER_H